package com.sp2p.service.admin;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.shove.base.BaseService;
import com.shove.data.DataException;
import com.shove.data.dao.MySQL;
import com.shove.vo.PageBean;
import com.sp2p.dao.admin.AccountPaymentDao;

public class AccountPaymentService extends BaseService {
	public static Log log = LogFactory.getLog(AccountPaymentService.class);

	private AccountPaymentDao accountPaymentDao;

	/**
	 * 增加支付方式
	 * 
	 * @param conn
	 * @param name
	 * @param nid
	 * @param status
	 * @param litpic
	 * @param style
	 * @param config
	 * @param description
	 * @param order
	 * @return
	 * @throws SQLException
	 * @throws SQLException
	 */
	public long addAccountPayment(String name, String nid, long status,
			String litpic, int style, String config, String description,
			int order) throws Exception {
		Connection conn = MySQL.getConnection();
		long result = -1L;
		try {
			result = accountPaymentDao.addAccountPayment(conn, name, nid,
					status, litpic, style, config, description, order);
			conn.commit();
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			conn.rollback();

			throw e;
		} finally {
			conn.close();
		}

		return result;

	}

	/**
	 * 分页查询所有
	 * 
	 * @param conn
	 * @param pageBean
	 * @throws DataException
	 * @throws Exception
	 */
	public void queryAccountPaymentPage(PageBean<Map<String, Object>> pageBean)
			throws Exception {
		Connection conn = MySQL.getConnection();
		try {
			accountPaymentDao.queryAccountPaymentPage(conn, pageBean);
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw e;
		} finally {
			conn.close();
		}
	}

	/**
	 * 修改
	 * 
	 * @param conn
	 * @param id
	 * @param name
	 * @param nid
	 * @param status
	 * @param litpic
	 * @param style
	 * @param config
	 * @param description
	 * @param order
	 * @return
	 * @throws Exception
	 */
	public long updateAccountPaymentPage(long id, String name, String litpic,
			String config, String description, int order) throws Exception {
		Connection conn = MySQL.getConnection();
		long result = -1L;
		try {
			result = accountPaymentDao.updateAccountPaymentPage(conn, id, name,
					litpic, config, description, order);
			conn.commit();
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			conn.rollback();

			throw e;
		} finally {
			conn.close();
		}
		return result;
	}

	/**
	 * 删除
	 * 
	 * @param conn
	 * @param id
	 * @return
	 * @throws Exception
	 * @throws Exception
	 */
	public long deleteAccountPaymentPage(long id, long status) throws Exception {
		Connection conn = MySQL.getConnection();
		long result = -1L;
		try {
			result = accountPaymentDao.deleteAccountPaymentPage(conn, id,
					status);
			conn.commit();
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			conn.rollback();

			throw e;
		} finally {
			conn.close();
		}

		return result;
	}

	/**
	 * 根据ID 查询
	 * 
	 * @param conn
	 * @param id
	 * @return
	 * @throws DataException
	 * @throws Exception
	 */
	public Map<String, String> queryAccountPaymentById(String nid)
			throws Exception {
		Connection conn = MySQL.getConnection();
		Map<String, String> map = null;
		try {
			map = accountPaymentDao.queryAccountPaymentById(conn, nid);
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw e;
		} finally {
			conn.close();
		}
		return map;
	}

	/**
	 * 查询所有支付信息
	 * 
	 * @return
	 * @throws Exception
	 * @throws DataException
	 */
	public List<Map<String, Object>> queryAccountPaymentList() throws Exception {
		Connection conn = MySQL.getConnection();
		List<Map<String, Object>> mapList = new ArrayList<Map<String, Object>>();
		try {
			mapList = accountPaymentDao.queryAccountPaymentList(conn);
		} catch (Exception e) {
			log.error(e);
			e.printStackTrace();
			throw e;
		} finally {
			conn.close();
		}
		return mapList;
	}

	public void setAccountPaymentDao(AccountPaymentDao accountPaymentDao) {
		this.accountPaymentDao = accountPaymentDao;
	}

}
